
#ifndef __CLINKDATE_H_20120712__
#define __CLINKDATE_H_20120712__

#include "LinkCtrl.h"

class CLinkDateEdit : public CEdit, public CLinkCtrl
{
public:
    CLinkDateEdit(INPUT_FIELD_INFO* pFieldInfo);
    virtual ~CLinkDateEdit();
	
	enum				{CtrlType = IBT_EditDate};
	virtual DWORD		GetControlType(){return CtrlType;}
	virtual CString		GetControlData(BOOL bTrimBlank = TRUE, BOOL bReplaceSingleQuotation = TRUE);
	virtual BOOL		CheckCtrlDataValid();

    void				SetDateTime(CTime dt);
	BOOL				SetToday();
	BOOL				CopyFrom(CLinkDateEdit* pFrom);
 
	CString				GetMask() const {return m_strMask;}

protected:
	virtual BOOL		PreTranslateMessage(MSG* pMsg);
	virtual void		PreSubclassWindow();
	
	virtual BOOL		OnCtrlKeyDown(UINT nKey);

private:
	BOOL				IsDateTimeValid();

private:
	BOOL				IsInRange(CString strNum, int nMin, int nMax);
	BOOL				IsLeapYear(int nYear);

    CString			m_strMask;
};


template<class TYPE>
void VSetInRange(TYPE &x, TYPE min, TYPE max) 
{
    ASSERT(min<=max);
    if (x < min) x = min; else if (x > max) x = max;
}

#endif//__CLINKDATE_H_20120712__